java如何链接首选项。xml到我的表格布局中的settingsTabFragment?
我需要添加设置到我的最后一个选项卡,并有数据可编辑,但我有困难这样做,不知道该使用哪些方法
我遵循的教程:https://github.com/codepath/安卓_guides/wiki/Settings-with-PreferenceFragment
设置StabFragment。爪哇
package com.example.sachin.pedometer;
import 安卓.content.Context;
import 安卓.net.Uri;
import 安卓.os.Bundle;
import 安卓.preference.ListPreference;
import 安卓.preference.Preference;
import 安卓.support.annotation.Nullable;
import 安卓.support.v4.app.Fragment;
import 安卓.view.LayoutInflater;
import 安卓.view.View;
import 安卓.view.ViewGroup;
import com.takisoft.fix.support.v7.preference.PreferenceFragmentCompat;
/**
* A simple {@link Fragment} subclass.
* Activities that contain this fragment must implement the
* {@link SettingsTabFragment.OnFragmentInteractionListener} interface
* to handle interaction events.
* Use the {@link SettingsTabFragment#newInstance} factory method to
* create an instance of this fragment.
*/
public class SettingsTabFragment extends PreferenceFragmentCompat {
private ListPreference mListPreference;
@Override
public void onCreatePreferencesFix(@Nullable Bundle savedInstanceState, String rootKey) {
// Indicate here the XML resource you created above that holds the preferences
setPreferencesFromResource(R.xml.preferences, rootKey);
}
/*@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
mListPreference = (ListPreference) getPreferenceManager().findPreference("preference_key");
mListPreference.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
// your code here
return view;
}
}
return inflater.inflate(R.layout.fragment_settings_tab, container, false);
}
}
# 1 楼答案
我真的不知道你的问题是什么!您是否未能实现ListPreference?当您尝试运行时,应用程序是否崩溃?如果是,请提供logcat
同时,试试这个
在你的
加上这个
在你的
加上这个